package com;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.InetAddress;
import java.net.Socket;

/**
 * @description: 测试 TCP请求端
 * @author: JYao
 * @create: 2021/01/19 14:20
 */
public class Test {

    public static void main(String[] args) throws IOException {
        // 建立tcp服务
        Socket socket = new Socket(InetAddress.getLocalHost(), 8883);
        //Socket socket = new Socket("120.53.236.19", 8883);

        // 获取socket输出流对象
        OutputStream outputStream = socket.getOutputStream();

        // 写数据
        String data = "HY:456,-123,000";
        outputStream.write(data.getBytes());

        // 与度武器端交互
        InputStream inputStream = socket.getInputStream();
        byte[] buf = new byte[1024];
        int length = inputStream.read(buf);
        System.out.println("客户端收到" + new String(buf, 0, length));

        // 关闭资源
        socket.close();
    }
}
